package com.atguigu.eduorder.service.impl;

import com.atguigu.commonutils.entity.CourseWebOrder;
import com.atguigu.commonutils.entity.UcenterMemberVo;
import com.atguigu.eduorder.client.EduClient;
import com.atguigu.eduorder.client.UcenterClient;
import com.atguigu.eduorder.entity.Order;
import com.atguigu.eduorder.mapper.OrderMapper;
import com.atguigu.eduorder.service.OrderService;
import com.atguigu.eduorder.utils.OrderNoUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author 董万均
 * @since 2020-11-07
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    private EduClient eduClient;
    @Autowired
    private UcenterClient ucenterClient;

    @Override
    public String createOrder(String courseId, String memberId) {
        //查询出课程的信息
        CourseWebOrder courseInfoOrder = eduClient.getCourseInfoOrder(courseId);
        //查询出用户的信息
        UcenterMemberVo userInfoOrder = ucenterClient.getUserInfo(memberId);
        //创建订单对象
        Order order=new Order();
        order.setCourseId(courseId);
        order.setCourseCover(courseInfoOrder.getCover());
        order.setCourseTitle(courseInfoOrder.getTitle());
        order.setTeacherName(courseInfoOrder.getTeacherName());
        order.setTotalFee(courseInfoOrder.getPrice());
        order.setMobile(userInfoOrder.getMobile());
        order.setMemberId(memberId);
        order.setNickname(userInfoOrder.getNickname());
        order.setStatus(0);
        order.setPayType(1);
        order.setOrderNo(OrderNoUtil.getOrderNo());

        baseMapper.insert(order);
        return order.getOrderNo();
    }
}
